home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Misc Servers / Zope.exe / XMLROLE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1999-07-21  |  24.7 KB  |  1,114 lines

  1. /*
  2. The contents of this file are subject to the Mozilla Public License
  3. Version 1.1 (the "License"); you may not use this file except in
  4. compliance with the License. You may obtain a copy of the License at
  5. http://www.mozilla.org/MPL/
  6.  
  7. Software distributed under the License is distributed on an "AS IS"
  8. basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  9. License for the specific language governing rights and limitations
  10. under the License.
  11.  
  12. The Original Code is expat.
  13.  
  14. The Initial Developer of the Original Code is James Clark.
  15. Portions created by James Clark are Copyright (C) 1998, 1999
  16. James Clark. All Rights Reserved.
  17.  
  18. Contributor(s):
  19.  
  20. Alternatively, the contents of this file may be used under the terms
  21. of the GNU General Public License (the "GPL"), in which case the
  22. provisions of the GPL are applicable instead of those above.  If you
  23. wish to allow use of your version of this file only under the terms of
  24. the GPL and not to allow others to use your version of this file under
  25. the MPL, indicate your decision by deleting the provisions above and
  26. replace them with the notice and other provisions required by the
  27. GPL. If you do not delete the provisions above, a recipient may use
  28. your version of this file under either the MPL or the GPL.
  29. */
  30.  
  31. #include "xmldef.h"
  32. #include "xmlrole.h"
  33.  
  34. /* Doesn't check:
  35.  
  36.  that ,| are not mixed in a model group
  37.  content of literals
  38.  
  39. */
  40.  
  41. #ifndef MIN_BYTES_PER_CHAR
  42. #define MIN_BYTES_PER_CHAR(enc) ((enc)->minBytesPerChar)
  43. #endif
  44.  
  45. typedef int PROLOG_HANDLER(struct prolog_state *state,
  46.                int tok,
  47.                const char *ptr,
  48.                const char *end,
  49.                const ENCODING *enc);
  50.  
  51. static PROLOG_HANDLER
  52.   prolog0, prolog1, prolog2,
  53.   doctype0, doctype1, doctype2, doctype3, doctype4, doctype5,
  54.   internalSubset,
  55.   entity0, entity1, entity2, entity3, entity4, entity5, entity6,
  56.   entity7, entity8, entity9,
  57.   notation0, notation1, notation2, notation3, notation4,
  58.   attlist0, attlist1, attlist2, attlist3, attlist4, attlist5, attlist6,
  59.   attlist7, attlist8, attlist9,
  60.   element0, element1, element2, element3, element4, element5, element6,
  61.   element7,
  62.   declClose,
  63.   error;
  64.  
  65. static
  66. int syntaxError(PROLOG_STATE *);
  67.  
  68. static
  69. int prolog0(PROLOG_STATE *state,
  70.         int tok,
  71.         const char *ptr,
  72.         const char *end,
  73.         const ENCODING *enc)
  74. {
  75.   switch (tok) {
  76.   case XML_TOK_PROLOG_S:
  77.     state->handler = prolog1;
  78.     return XML_ROLE_NONE;
  79.   case XML_TOK_XML_DECL:
  80.     state->handler = prolog1;
  81.     return XML_ROLE_XML_DECL;
  82.   case XML_TOK_PI:
  83.     state->handler = prolog1;
  84.     return XML_ROLE_NONE;
  85.   case XML_TOK_COMMENT:
  86.     state->handler = prolog1;
  87.   case XML_TOK_BOM:
  88.     return XML_ROLE_NONE;
  89.   case XML_TOK_DECL_OPEN:
  90.     if (!XmlNameMatchesAscii(enc,
  91.                  ptr + 2 * MIN_BYTES_PER_CHAR(enc),
  92.                  "DOCTYPE"))
  93.       break;
  94.     state->handler = doctype0;
  95.     return XML_ROLE_NONE;
  96.   case XML_TOK_INSTANCE_START:
  97.     state->handler = error;
  98.     return XML_ROLE_INSTANCE_START;
  99.   }
  100.   return syntaxError(state);
  101. }
  102.  
  103. static
  104. int prolog1(PROLOG_STATE *state,
  105.         int tok,
  106.         const char *ptr,
  107.         const char *end,
  108.         const ENCODING *enc)
  109. {
  110.   switch (tok) {
  111.   case XML_TOK_PROLOG_S:
  112.     return XML_ROLE_NONE;
  113.   case XML_TOK_PI:
  114.   case XML_TOK_COMMENT:
  115.   case XML_TOK_BOM:
  116.     return XML_ROLE_NONE;
  117.   case XML_TOK_DECL_OPEN:
  118.     if (!XmlNameMatchesAscii(enc,
  119.                  ptr + 2 * MIN_BYTES_PER_CHAR(enc),
  120.                  "DOCTYPE"))
  121.       break;
  122.     state->handler = doctype0;
  123.     return XML_ROLE_NONE;
  124.   case XML_TOK_INSTANCE_START:
  125.     state->handler = error;
  126.     return XML_ROLE_INSTANCE_START;
  127.   }
  128.   return syntaxError(state);
  129. }
  130.  
  131. static
  132. int prolog2(PROLOG_STATE *state,
  133.         int tok,
  134.         const char *ptr,
  135.         const char *end,
  136.         const ENCODING *enc)
  137. {
  138.   switch (tok) {
  139.   case XML_TOK_PROLOG_S:
  140.     return XML_ROLE_NONE;
  141.   case XML_TOK_PI:
  142.   case XML_TOK_COMMENT:
  143.     return XML_ROLE_NONE;
  144.   case XML_TOK_INSTANCE_START:
  145.     state->handler = error;
  146.     return XML_ROLE_INSTANCE_START;
  147.   }
  148.   return syntaxError(state);
  149. }
  150.  
  151. static
  152. int doctype0(PROLOG_STATE *state,
  153.          int tok,
  154.          const char *ptr,
  155.          const char *end,
  156.          const ENCODING *enc)
  157. {
  158.   switch (tok) {
  159.   case XML_TOK_PROLOG_S:
  160.     return XML_ROLE_NONE;
  161.   case XML_TOK_NAME:
  162.   case XML_TOK_PREFIXED_NAME:
  163.     state->handler = doctype1;
  164.     return XML_ROLE_DOCTYPE_NAME;
  165.   }
  166.   return syntaxError(state);
  167. }
  168.  
  169. static
  170. int doctype1(PROLOG_STATE *state,
  171.          int tok,
  172.          const char *ptr,
  173.          const char *end,
  174.          const ENCODING *enc)
  175. {
  176.   switch (tok) {
  177.   case XML_TOK_PROLOG_S:
  178.     return XML_ROLE_NONE;
  179.   case XML_TOK_OPEN_BRACKET:
  180.     state->handler = internalSubset;
  181.     return XML_ROLE_NONE;
  182.   case XML_TOK_DECL_CLOSE:
  183.     state->handler = prolog2;
  184.     return XML_ROLE_DOCTYPE_CLOSE;
  185.   case XML_TOK_NAME:
  186.     if (XmlNameMatchesAscii(enc, ptr, "SYSTEM")) {
  187.       state->handler = doctype3;
  188.       return XML_ROLE_NONE;
  189.     }
  190.     if (XmlNameMatchesAscii(enc, ptr, "PUBLIC")) {
  191.       state->handler = doctype2;
  192.       return XML_ROLE_NONE;
  193.     }
  194.     break;
  195.   }
  196.   return syntaxError(state);
  197. }
  198.  
  199. static
  200. int doctype2(PROLOG_STATE *state,
  201.          int tok,
  202.          const char *ptr,
  203.          const char *end,
  204.          const ENCODING *enc)
  205. {
  206.   switch (tok) {
  207.   case XML_TOK_PROLOG_S:
  208.     return XML_ROLE_NONE;
  209.   case XML_TOK_LITERAL:
  210.     state->handler = doctype3;
  211.     return XML_ROLE_DOCTYPE_PUBLIC_ID;
  212.   }
  213.   return syntaxError(state);
  214. }
  215.  
  216. static
  217. int doctype3(PROLOG_STATE *state,
  218.          int tok,
  219.          const char *ptr,
  220.          const char *end,
  221.          const ENCODING *enc)
  222. {
  223.   switch (tok) {
  224.   case XML_TOK_PROLOG_S:
  225.     return XML_ROLE_NONE;
  226.   case XML_TOK_LITERAL:
  227.     state->handler = doctype4;
  228.     return XML_ROLE_DOCTYPE_SYSTEM_ID;
  229.   }
  230.   return syntaxError(state);
  231. }
  232.  
  233. static
  234. int doctype4(PROLOG_STATE *state,
  235.          int tok,
  236.          const char *ptr,
  237.          const char *end,
  238.          const ENCODING *enc)
  239. {
  240.   switch (tok) {
  241.   case XML_TOK_PROLOG_S:
  242.     return XML_ROLE_NONE;
  243.   case XML_TOK_OPEN_BRACKET:
  244.     state->handler = internalSubset;
  245.     return XML_ROLE_NONE;
  246.   case XML_TOK_DECL_CLOSE:
  247.     state->handler = prolog2;
  248.     return XML_ROLE_DOCTYPE_CLOSE;
  249.   }
  250.   return syntaxError(state);
  251. }
  252.  
  253. static
  254. int doctype5(PROLOG_STATE *state,
  255.          int tok,
  256.          const char *ptr,
  257.          const char *end,
  258.          const ENCODING *enc)
  259. {
  260.   switch (tok) {
  261.   case XML_TOK_PROLOG_S:
  262.     return XML_ROLE_NONE;
  263.   case XML_TOK_DECL_CLOSE:
  264.     state->handler = prolog2;
  265.     return XML_ROLE_DOCTYPE_CLOSE;
  266.   }
  267.   return syntaxError(state);
  268. }
  269.  
  270. static
  271. int internalSubset(PROLOG_STATE *state,
  272.            int tok,
  273.            const char *ptr,
  274.            const char *end,
  275.            const ENCODING *enc)
  276. {
  277.   switch (tok) {
  278.   case XML_TOK_PROLOG_S:
  279.     return XML_ROLE_NONE;
  280.   case XML_TOK_DECL_OPEN:
  281.     if (XmlNameMatchesAscii(enc,
  282.                 ptr + 2 * MIN_BYTES_PER_CHAR(enc),
  283.                 "ENTITY")) {
  284.       state->handler = entity0;
  285.       return XML_ROLE_NONE;
  286.     }
  287.     if (XmlNameMatchesAscii(enc,
  288.                 ptr + 2 * MIN_BYTES_PER_CHAR(enc),
  289.                 "ATTLIST")) {
  290.       state->handler = attlist0;
  291.       return XML_ROLE_NONE;
  292.     }
  293.     if (XmlNameMatchesAscii(enc,
  294.                 ptr + 2 * MIN_BYTES_PER_CHAR(enc),
  295.                 "ELEMENT")) {
  296.       state->handler = element0;
  297.       return XML_ROLE_NONE;
  298.     }
  299.     if (XmlNameMatchesAscii(enc,
  300.                 ptr + 2 * MIN_BYTES_PER_CHAR(enc),
  301.                 "NOTATION")) {
  302.       state->handler = notation0;
  303.       return XML_ROLE_NONE;
  304.     }
  305.     break;
  306.   case XML_TOK_PI:
  307.   case XML_TOK_COMMENT:
  308.     return XML_ROLE_NONE;
  309.   case XML_TOK_PARAM_ENTITY_REF:
  310.     return XML_ROLE_PARAM_ENTITY_REF;
  311.   case XML_TOK_CLOSE_BRACKET:
  312.     state->handler = doctype5;
  313.     return XML_ROLE_NONE;
  314.   }
  315.   return syntaxError(state);
  316. }
  317.  
  318. static
  319. int entity0(PROLOG_STATE *state,
  320.         int tok,
  321.         const char *ptr,
  322.         const char *end,
  323.         const ENCODING *enc)
  324. {
  325.   switch (tok) {
  326.   case XML_TOK_PROLOG_S:
  327.     return XML_ROLE_NONE;
  328.   case XML_TOK_PERCENT:
  329.     state->handler = entity1;
  330.     return XML_ROLE_NONE;
  331.   case XML_TOK_NAME:
  332.     state->handler = entity2;
  333.     return XML_ROLE_GENERAL_ENTITY_NAME;
  334.   }
  335.   return syntaxError(state);
  336. }
  337.  
  338. static
  339. int entity1(PROLOG_STATE *state,
  340.         int tok,
  341.         const char *ptr,
  342.         const char *end,
  343.         const ENCODING *enc)
  344. {
  345.   switch (tok) {
  346.   case XML_TOK_PROLOG_S:
  347.     return XML_ROLE_NONE;
  348.   case XML_TOK_NAME:
  349.     state->handler = entity7;
  350.     return XML_ROLE_PARAM_ENTITY_NAME;
  351.   }
  352.   return syntaxError(state);
  353. }
  354.  
  355. static
  356. int entity2(PROLOG_STATE *state,
  357.         int tok,
  358.         const char *ptr,
  359.         const char *end,
  360.         const ENCODING *enc)
  361. {
  362.   switch (tok) {
  363.   case XML_TOK_PROLOG_S:
  364.     return XML_ROLE_NONE;
  365.   case XML_TOK_NAME:
  366.     if (XmlNameMatchesAscii(enc, ptr, "SYSTEM")) {
  367.       state->handler = entity4;
  368.       return XML_ROLE_NONE;
  369.     }
  370.     if (XmlNameMatchesAscii(enc, ptr, "PUBLIC")) {
  371.       state->handler = entity3;
  372.       return XML_ROLE_NONE;
  373.     }
  374.     break;
  375.   case XML_TOK_LITERAL:
  376.     state->handler = declClose;
  377.     return XML_ROLE_ENTITY_VALUE;
  378.   }
  379.   return syntaxError(state);
  380. }
  381.  
  382. static
  383. int entity3(PROLOG_STATE *state,
  384.         int tok,
  385.         const char *ptr,
  386.         const char *end,
  387.         const ENCODING *enc)
  388. {
  389.   switch (tok) {
  390.   case XML_TOK_PROLOG_S:
  391.     return XML_ROLE_NONE;
  392.   case XML_TOK_LITERAL:
  393.     state->handler = entity4;
  394.     return XML_ROLE_ENTITY_PUBLIC_ID;
  395.   }
  396.   return syntaxError(state);
  397. }
  398.  
  399.  
  400. static
  401. int entity4(PROLOG_STATE *state,
  402.         int tok,
  403.         const char *ptr,
  404.         const char *end,
  405.         const ENCODING *enc)
  406. {
  407.   switch (tok) {
  408.   case XML_TOK_PROLOG_S:
  409.     return XML_ROLE_NONE;
  410.   case XML_TOK_LITERAL:
  411.     state->handler = entity5;
  412.     return XML_ROLE_ENTITY_SYSTEM_ID;
  413.   }
  414.   return syntaxError(state);
  415. }
  416.  
  417. static
  418. int entity5(PROLOG_STATE *state,
  419.         int tok,
  420.         const char *ptr,
  421.         const char *end,
  422.         const ENCODING *enc)
  423. {
  424.   switch (tok) {
  425.   case XML_TOK_PROLOG_S:
  426.     return XML_ROLE_NONE;
  427.   case XML_TOK_DECL_CLOSE:
  428.     state->handler = internalSubset;
  429.     return XML_ROLE_NONE;
  430.   case XML_TOK_NAME:
  431.     if (XmlNameMatchesAscii(enc, ptr, "NDATA")) {
  432.       state->handler = entity6;
  433.       return XML_ROLE_NONE;
  434.     }
  435.     break;
  436.   }
  437.   return syntaxError(state);
  438. }
  439.  
  440. static
  441. int entity6(PROLOG_STATE *state,
  442.         int tok,
  443.         const char *ptr,
  444.         const char *end,
  445.         const ENCODING *enc)
  446. {
  447.   switch (tok) {
  448.   case XML_TOK_PROLOG_S:
  449.     return XML_ROLE_NONE;
  450.   case XML_TOK_NAME:
  451.     state->handler = declClose;
  452.     return XML_ROLE_ENTITY_NOTATION_NAME;
  453.   }
  454.   return syntaxError(state);
  455. }
  456.  
  457. static
  458. int entity7(PROLOG_STATE *state,
  459.         int tok,
  460.         const char *ptr,
  461.         const char *end,
  462.         const ENCODING *enc)
  463. {
  464.   switch (tok) {
  465.   case XML_TOK_PROLOG_S:
  466.     return XML_ROLE_NONE;
  467.   case XML_TOK_NAME:
  468.     if (XmlNameMatchesAscii(enc, ptr, "SYSTEM")) {
  469.       state->handler = entity9;
  470.       return XML_ROLE_NONE;
  471.     }
  472.     if (XmlNameMatchesAscii(enc, ptr, "PUBLIC")) {
  473.       state->handler = entity8;
  474.       return XML_ROLE_NONE;
  475.     }
  476.     break;
  477.   case XML_TOK_LITERAL:
  478.     state->handler = declClose;
  479.     return XML_ROLE_ENTITY_VALUE;
  480.   }
  481.   return syntaxError(state);
  482. }
  483.  
  484. static
  485. int entity8(PROLOG_STATE *state,
  486.         int tok,
  487.         const char *ptr,
  488.         const char *end,
  489.         const ENCODING *enc)
  490. {
  491.   switch (tok) {
  492.   case XML_TOK_PROLOG_S:
  493.     return XML_ROLE_NONE;
  494.   case XML_TOK_LITERAL:
  495.     state->handler = entity9;
  496.     return XML_ROLE_ENTITY_PUBLIC_ID;
  497.   }
  498.   return syntaxError(state);
  499. }
  500.  
  501. static
  502. int entity9(PROLOG_STATE *state,
  503.         int tok,
  504.         const char *ptr,
  505.         const char *end,
  506.         const ENCODING *enc)
  507. {
  508.   switch (tok) {
  509.   case XML_TOK_PROLOG_S:
  510.     return XML_ROLE_NONE;
  511.   case XML_TOK_LITERAL:
  512.     state->handler = declClose;
  513.     return XML_ROLE_ENTITY_SYSTEM_ID;
  514.   }
  515.   return syntaxError(state);
  516. }
  517.  
  518. static
  519. int notation0(PROLOG_STATE *state,
  520.           int tok,
  521.           const char *ptr,
  522.           const char *end,
  523.           const ENCODING *enc)
  524. {
  525.   switch (tok) {
  526.   case XML_TOK_PROLOG_S:
  527.     return XML_ROLE_NONE;
  528.   case XML_TOK_NAME:
  529.     state->handler = notation1;
  530.     return XML_ROLE_NOTATION_NAME;
  531.   }
  532.   return syntaxError(state);
  533. }
  534.  
  535. static
  536. int notation1(PROLOG_STATE *state,
  537.           int tok,
  538.           const char *ptr,
  539.           const char *end,
  540.           const ENCODING *enc)
  541. {
  542.   switch (tok) {
  543.   case XML_TOK_PROLOG_S:
  544.     return XML_ROLE_NONE;
  545.   case XML_TOK_NAME:
  546.     if (XmlNameMatchesAscii(enc, ptr, "SYSTEM")) {
  547.       state->handler = notation3;
  548.       return XML_ROLE_NONE;
  549.     }
  550.     if (XmlNameMatchesAscii(enc, ptr, "PUBLIC")) {
  551.       state->handler = notation2;
  552.       return XML_ROLE_NONE;
  553.     }
  554.     break;
  555.   }
  556.   return syntaxError(state);
  557. }
  558.  
  559. static
  560. int notation2(PROLOG_STATE *state,
  561.           int tok,
  562.           const char *ptr,
  563.           const char *end,
  564.           const ENCODING *enc)
  565. {
  566.   switch (tok) {
  567.   case XML_TOK_PROLOG_S:
  568.     return XML_ROLE_NONE;
  569.   case XML_TOK_LITERAL:
  570.     state->handler = notation4;
  571.     return XML_ROLE_NOTATION_PUBLIC_ID;
  572.   }
  573.   return syntaxError(state);
  574. }
  575.  
  576. static
  577. int notation3(PROLOG_STATE *state,
  578.           int tok,
  579.           const char *ptr,
  580.           const char *end,
  581.           const ENCODING *enc)
  582. {
  583.   switch (tok) {
  584.   case XML_TOK_PROLOG_S:
  585.     return XML_ROLE_NONE;
  586.   case XML_TOK_LITERAL:
  587.     state->handler = declClose;
  588.     return XML_ROLE_NOTATION_SYSTEM_ID;
  589.   }
  590.   return syntaxError(state);
  591. }
  592.  
  593. static
  594. int notation4(PROLOG_STATE *state,
  595.           int tok,
  596.           const char *ptr,
  597.           const char *end,
  598.           const ENCODING *enc)
  599. {
  600.   switch (tok) {
  601.   case XML_TOK_PROLOG_S:
  602.     return XML_ROLE_NONE;
  603.   case XML_TOK_LITERAL:
  604.     state->handler = declClose;
  605.     return XML_ROLE_NOTATION_SYSTEM_ID;
  606.   case XML_TOK_DECL_CLOSE:
  607.     state->handler = internalSubset;
  608.     return XML_ROLE_NOTATION_NO_SYSTEM_ID;
  609.   }
  610.   return syntaxError(state);
  611. }
  612.  
  613. static
  614. int attlist0(PROLOG_STATE *state,
  615.          int tok,
  616.          const char *ptr,
  617.          const char *end,
  618.          const ENCODING *enc)
  619. {
  620.   switch (tok) {
  621.   case XML_TOK_PROLOG_S:
  622.     return XML_ROLE_NONE;
  623.   case XML_TOK_NAME:
  624.   case XML_TOK_PREFIXED_NAME:
  625.     state->handler = attlist1;
  626.     return XML_ROLE_ATTLIST_ELEMENT_NAME;
  627.   }
  628.   return syntaxError(state);
  629. }
  630.  
  631. static
  632. int attlist1(PROLOG_STATE *state,
  633.          int tok,
  634.          const char *ptr,
  635.          const char *end,
  636.          const ENCODING *enc)
  637. {
  638.   switch (tok) {
  639.   case XML_TOK_PROLOG_S:
  640.     return XML_ROLE_NONE;
  641.   case XML_TOK_DECL_CLOSE:
  642.     state->handler = internalSubset;
  643.     return XML_ROLE_NONE;
  644.   case XML_TOK_NAME:
  645.   case XML_TOK_PREFIXED_NAME:
  646.     state->handler = attlist2;
  647.     return XML_ROLE_ATTRIBUTE_NAME;
  648.   }
  649.   return syntaxError(state);
  650. }
  651.  
  652. static
  653. int attlist2(PROLOG_STATE *state,
  654.          int tok,
  655.          const char *ptr,
  656.          const char *end,
  657.          const ENCODING *enc)
  658. {
  659.   switch (tok) {
  660.   case XML_TOK_PROLOG_S:
  661.     return XML_ROLE_NONE;
  662.   case XML_TOK_NAME:
  663.     {
  664.       static const char *types[] = {
  665.     "CDATA",
  666.         "ID",
  667.         "IDREF",
  668.         "IDREFS",
  669.         "ENTITY",
  670.         "ENTITIES",
  671.         "NMTOKEN",
  672.         "NMTOKENS",
  673.       };
  674.       int i;
  675.       for (i = 0; i < (int)(sizeof(types)/sizeof(types[0])); i++)
  676.     if (XmlNameMatchesAscii(enc, ptr, types[i])) {
  677.       state->handler = attlist8;
  678.       return XML_ROLE_ATTRIBUTE_TYPE_CDATA + i;
  679.     }
  680.     }
  681.     if (XmlNameMatchesAscii(enc, ptr, "NOTATION")) {
  682.       state->handler = attlist5;
  683.       return XML_ROLE_NONE;
  684.     }
  685.     break;
  686.   case XML_TOK_OPEN_PAREN:
  687.     state->handler = attlist3;
  688.     return XML_ROLE_NONE;
  689.   }
  690.   return syntaxError(state);
  691. }
  692.  
  693. static
  694. int attlist3(PROLOG_STATE *state,
  695.          int tok,
  696.          const char *ptr,
  697.          const char *end,
  698.          const ENCODING *enc)
  699. {
  700.   switch (tok) {
  701.   case XML_TOK_PROLOG_S:
  702.     return XML_ROLE_NONE;
  703.   case XML_TOK_NMTOKEN:
  704.   case XML_TOK_NAME:
  705.   case XML_TOK_PREFIXED_NAME:
  706.     state->handler = attlist4;
  707.     return XML_ROLE_ATTRIBUTE_ENUM_VALUE;
  708.   }
  709.   return syntaxError(state);
  710. }
  711.  
  712. static
  713. int attlist4(PROLOG_STATE *state,
  714.          int tok,
  715.          const char *ptr,
  716.          const char *end,
  717.          const ENCODING *enc)
  718. {
  719.   switch (tok) {
  720.   case XML_TOK_PROLOG_S:
  721.     return XML_ROLE_NONE;
  722.   case XML_TOK_CLOSE_PAREN:
  723.     state->handler = attlist8;
  724.     return XML_ROLE_NONE;
  725.   case XML_TOK_OR:
  726.     state->handler = attlist3;
  727.     return XML_ROLE_NONE;
  728.   }
  729.   return syntaxError(state);
  730. }
  731.  
  732. static
  733. int attlist5(PROLOG_STATE *state,
  734.          int tok,
  735.          const char *ptr,
  736.          const char *end,
  737.          const ENCODING *enc)
  738. {
  739.   switch (tok) {
  740.   case XML_TOK_PROLOG_S:
  741.     return XML_ROLE_NONE;
  742.   case XML_TOK_OPEN_PAREN:
  743.     state->handler = attlist6;
  744.     return XML_ROLE_NONE;
  745.   }
  746.   return syntaxError(state);
  747. }
  748.  
  749.  
  750. static
  751. int attlist6(PROLOG_STATE *state,
  752.          int tok,
  753.          const char *ptr,
  754.          const char *end,
  755.          const ENCODING *enc)
  756. {
  757.   switch (tok) {
  758.   case XML_TOK_PROLOG_S:
  759.     return XML_ROLE_NONE;
  760.   case XML_TOK_NAME:
  761.     state->handler = attlist7;
  762.     return XML_ROLE_ATTRIBUTE_NOTATION_VALUE;
  763.   }
  764.   return syntaxError(state);
  765. }
  766.  
  767. static
  768. int attlist7(PROLOG_STATE *state,
  769.          int tok,
  770.          const char *ptr,
  771.          const char *end,
  772.          const ENCODING *enc)
  773. {
  774.   switch (tok) {
  775.   case XML_TOK_PROLOG_S:
  776.     return XML_ROLE_NONE;
  777.   case XML_TOK_CLOSE_PAREN:
  778.     state->handler = attlist8;
  779.     return XML_ROLE_NONE;
  780.   case XML_TOK_OR:
  781.     state->handler = attlist6;
  782.     return XML_ROLE_NONE;
  783.   }
  784.   return syntaxError(state);
  785. }
  786.  
  787. /* default value */
  788. static
  789. int attlist8(PROLOG_STATE *state,
  790.          int tok,
  791.          const char *ptr,
  792.          const char *end,
  793.          const ENCODING *enc)
  794. {
  795.   switch (tok) {
  796.   case XML_TOK_PROLOG_S:
  797.     return XML_ROLE_NONE;
  798.   case XML_TOK_POUND_NAME:
  799.     if (XmlNameMatchesAscii(enc,
  800.                 ptr + MIN_BYTES_PER_CHAR(enc),
  801.                 "IMPLIED")) {
  802.       state->handler = attlist1;
  803.       return XML_ROLE_IMPLIED_ATTRIBUTE_VALUE;
  804.     }
  805.     if (XmlNameMatchesAscii(enc,
  806.                 ptr + MIN_BYTES_PER_CHAR(enc),
  807.                 "REQUIRED")) {
  808.       state->handler = attlist1;
  809.       return XML_ROLE_REQUIRED_ATTRIBUTE_VALUE;
  810.     }
  811.     if (XmlNameMatchesAscii(enc,
  812.                 ptr + MIN_BYTES_PER_CHAR(enc),
  813.                 "FIXED")) {
  814.       state->handler = attlist9;
  815.       return XML_ROLE_NONE;
  816.     }
  817.     break;
  818.   case XML_TOK_LITERAL:
  819.     state->handler = attlist1;
  820.     return XML_ROLE_DEFAULT_ATTRIBUTE_VALUE;
  821.   }
  822.   return syntaxError(state);
  823. }
  824.  
  825. static
  826. int attlist9(PROLOG_STATE *state,
  827.          int tok,
  828.          const char *ptr,
  829.          const char *end,
  830.          const ENCODING *enc)
  831. {
  832.   switch (tok) {
  833.   case XML_TOK_PROLOG_S:
  834.     return XML_ROLE_NONE;
  835.   case XML_TOK_LITERAL:
  836.     state->handler = attlist1;
  837.     return XML_ROLE_FIXED_ATTRIBUTE_VALUE;
  838.   }
  839.   return syntaxError(state);
  840. }
  841.  
  842. static
  843. int element0(PROLOG_STATE *state,
  844.          int tok,
  845.          const char *ptr,
  846.          const char *end,
  847.          const ENCODING *enc)
  848. {
  849.   switch (tok) {
  850.   case XML_TOK_PROLOG_S:
  851.     return XML_ROLE_NONE;
  852.   case XML_TOK_NAME:
  853.   case XML_TOK_PREFIXED_NAME:
  854.     state->handler = element1;
  855.     return XML_ROLE_ELEMENT_NAME;
  856.   }
  857.   return syntaxError(state);
  858. }
  859.  
  860. static
  861. int element1(PROLOG_STATE *state,
  862.          int tok,
  863.          const char *ptr,
  864.          const char *end,
  865.          const ENCODING *enc)
  866. {
  867.   switch (tok) {
  868.   case XML_TOK_PROLOG_S:
  869.     return XML_ROLE_NONE;
  870.   case XML_TOK_NAME:
  871.     if (XmlNameMatchesAscii(enc, ptr, "EMPTY")) {
  872.       state->handler = declClose;
  873.       return XML_ROLE_CONTENT_EMPTY;
  874.     }
  875.     if (XmlNameMatchesAscii(enc, ptr, "ANY")) {
  876.       state->handler = declClose;
  877.       return XML_ROLE_CONTENT_ANY;
  878.     }
  879.     break;
  880.   case XML_TOK_OPEN_PAREN:
  881.     state->handler = element2;
  882.     state->level = 1;
  883.     return XML_ROLE_GROUP_OPEN;
  884.   }
  885.   return syntaxError(state);
  886. }
  887.  
  888. static
  889. int element2(PROLOG_STATE *state,
  890.          int tok,
  891.          const char *ptr,
  892.          const char *end,
  893.          const ENCODING *enc)
  894. {
  895.   switch (tok) {
  896.   case XML_TOK_PROLOG_S:
  897.     return XML_ROLE_NONE;
  898.   case XML_TOK_POUND_NAME:
  899.     if (XmlNameMatchesAscii(enc,
  900.                 ptr + MIN_BYTES_PER_CHAR(enc),
  901.                 "PCDATA")) {
  902.       state->handler = element3;
  903.       return XML_ROLE_CONTENT_PCDATA;
  904.     }
  905.     break;
  906.   case XML_TOK_OPEN_PAREN:
  907.     state->level = 2;
  908.     state->handler = element6;
  909.     return XML_ROLE_GROUP_OPEN;
  910.   case XML_TOK_NAME:
  911.   case XML_TOK_PREFIXED_NAME:
  912.     state->handler = element7;
  913.     return XML_ROLE_CONTENT_ELEMENT;
  914.   case XML_TOK_NAME_QUESTION:
  915.     state->handler = element7;
  916.     return XML_ROLE_CONTENT_ELEMENT_OPT;
  917.   case XML_TOK_NAME_ASTERISK:
  918.     state->handler = element7;
  919.     return XML_ROLE_CONTENT_ELEMENT_REP;
  920.   case XML_TOK_NAME_PLUS:
  921.     state->handler = element7;
  922.     return XML_ROLE_CONTENT_ELEMENT_PLUS;
  923.   }
  924.   return syntaxError(state);
  925. }
  926.  
  927. static
  928. int element3(PROLOG_STATE *state,
  929.          int tok,
  930.          const char *ptr,
  931.          const char *end,
  932.          const ENCODING *enc)
  933. {
  934.   switch (tok) {
  935.   case XML_TOK_PROLOG_S:
  936.     return XML_ROLE_NONE;
  937.   case XML_TOK_CLOSE_PAREN:
  938.   case XML_TOK_CLOSE_PAREN_ASTERISK:
  939.     state->handler = declClose;
  940.     return XML_ROLE_GROUP_CLOSE_REP;
  941.   case XML_TOK_OR:
  942.     state->handler = element4;
  943.     return XML_ROLE_NONE;
  944.   }
  945.   return syntaxError(state);
  946. }
  947.  
  948. static
  949. int element4(PROLOG_STATE *state,
  950.          int tok,
  951.          const char *ptr,
  952.          const char *end,
  953.          const ENCODING *enc)
  954. {
  955.   switch (tok) {
  956.   case XML_TOK_PROLOG_S:
  957.     return XML_ROLE_NONE;
  958.   case XML_TOK_NAME:
  959.   case XML_TOK_PREFIXED_NAME:
  960.     state->handler = element5;
  961.     return XML_ROLE_CONTENT_ELEMENT;
  962.   }
  963.   return syntaxError(state);
  964. }
  965.  
  966. static
  967. int element5(PROLOG_STATE *state,
  968.          int tok,
  969.          const char *ptr,
  970.          const char *end,
  971.          const ENCODING *enc)
  972. {
  973.   switch (tok) {
  974.   case XML_TOK_PROLOG_S:
  975.     return XML_ROLE_NONE;
  976.   case XML_TOK_CLOSE_PAREN_ASTERISK:
  977.     state->handler = declClose;
  978.     return XML_ROLE_GROUP_CLOSE_REP;
  979.   case XML_TOK_OR:
  980.     state->handler = element4;
  981.     return XML_ROLE_NONE;
  982.   }
  983.   return syntaxError(state);
  984. }
  985.  
  986. static
  987. int element6(PROLOG_STATE *state,
  988.          int tok,
  989.          const char *ptr,
  990.          const char *end,
  991.          const ENCODING *enc)
  992. {
  993.   switch (tok) {
  994.   case XML_TOK_PROLOG_S:
  995.     return XML_ROLE_NONE;
  996.   case XML_TOK_OPEN_PAREN:
  997.     state->level += 1;
  998.     return XML_ROLE_GROUP_OPEN;
  999.   case XML_TOK_NAME:
  1000.   case XML_TOK_PREFIXED_NAME:
  1001.     state->handler = element7;
  1002.     return XML_ROLE_CONTENT_ELEMENT;
  1003.   case XML_TOK_NAME_QUESTION:
  1004.     state->handler = element7;
  1005.     return XML_ROLE_CONTENT_ELEMENT_OPT;
  1006.   case XML_TOK_NAME_ASTERISK:
  1007.     state->handler = element7;
  1008.     return XML_ROLE_CONTENT_ELEMENT_REP;
  1009.   case XML_TOK_NAME_PLUS:
  1010.     state->handler = element7;
  1011.     return XML_ROLE_CONTENT_ELEMENT_PLUS;
  1012.   }
  1013.   return syntaxError(state);
  1014. }
  1015.  
  1016. static
  1017. int element7(PROLOG_STATE *state,
  1018.          int tok,
  1019.          const char *ptr,
  1020.          const char *end,
  1021.          const ENCODING *enc)
  1022. {
  1023.   switch (tok) {
  1024.   case XML_TOK_PROLOG_S:
  1025.     return XML_ROLE_NONE;
  1026.   case XML_TOK_CLOSE_PAREN:
  1027.     state->level -= 1;
  1028.     if (state->level == 0)
  1029.       state->handler = declClose;
  1030.     return XML_ROLE_GROUP_CLOSE;
  1031.   case XML_TOK_CLOSE_PAREN_ASTERISK:
  1032.     state->level -= 1;
  1033.     if (state->level == 0)
  1034.       state->handler = declClose;
  1035.     return XML_ROLE_GROUP_CLOSE_REP;
  1036.   case XML_TOK_CLOSE_PAREN_QUESTION:
  1037.     state->level -= 1;
  1038.     if (state->level == 0)
  1039.       state->handler = declClose;
  1040.     return XML_ROLE_GROUP_CLOSE_OPT;
  1041.   case XML_TOK_CLOSE_PAREN_PLUS:
  1042.     state->level -= 1;
  1043.     if (state->level == 0)
  1044.       state->handler = declClose;
  1045.     return XML_ROLE_GROUP_CLOSE_PLUS;
  1046.   case XML_TOK_COMMA:
  1047.     state->handler = element6;
  1048.     return XML_ROLE_GROUP_SEQUENCE;
  1049.   case XML_TOK_OR:
  1050.     state->handler = element6;
  1051.     return XML_ROLE_GROUP_CHOICE;
  1052.   }
  1053.   return syntaxError(state);
  1054. }
  1055.  
  1056. static
  1057. int declClose(PROLOG_STATE *state,
  1058.           int tok,
  1059.           const char *ptr,
  1060.           const char *end,
  1061.           const ENCODING *enc)
  1062. {
  1063.   switch (tok) {
  1064.   case XML_TOK_PROLOG_S:
  1065.     return XML_ROLE_NONE;
  1066.   case XML_TOK_DECL_CLOSE:
  1067.     state->handler = internalSubset;
  1068.     return XML_ROLE_NONE;
  1069.   }
  1070.   return syntaxError(state);
  1071. }
  1072.  
  1073. #if 0
  1074.  
  1075. static
  1076. int ignore(PROLOG_STATE *state,
  1077.        int tok,
  1078.        const char *ptr,
  1079.        const char *end,
  1080.        const ENCODING *enc)
  1081. {
  1082.   switch (tok) {
  1083.   case XML_TOK_DECL_CLOSE:
  1084.     state->handler = internalSubset;
  1085.     return 0;
  1086.   default:
  1087.     return XML_ROLE_NONE;
  1088.   }
  1089.   return syntaxError(state);
  1090. }
  1091. #endif
  1092.  
  1093. static
  1094. int error(PROLOG_STATE *state,
  1095.        int tok,
  1096.        const char *ptr,
  1097.        const char *end,
  1098.        const ENCODING *enc)
  1099. {
  1100.   return XML_ROLE_NONE;
  1101. }
  1102.  
  1103. static
  1104. int syntaxError(PROLOG_STATE *state)
  1105. {
  1106.   state->handler = error;
  1107.   return XML_ROLE_ERROR;
  1108. }
  1109.  
  1110. void XmlPrologStateInit(PROLOG_STATE *state)
  1111. {
  1112.   state->handler = prolog0;
  1113. }
  1114.